﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public partial class Scheduling : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql = string.Format("select * from Doctor");
            SqlDataReader re = DBHelper.GetDataReader(sql);
            ArrayList ID = new ArrayList();
            while (re.Read())
            {
                ID.Add(re["ID"].ToString());
            }
            re.Close();
            DropDownList3.DataSource = ID;
            DropDownList3.DataBind();
            Page.DataBind();
        }
    }

    protected void DropDownList3_TextChanged(object sender, EventArgs e)
    {
        string ID = "";
        ID = DropDownList3.SelectedValue.ToString();
        string sql = string.Format("select * from Doctor where ID='{0}'", ID);
        SqlDataReader re = DBHelper.GetDataReader(sql);
        while (re.Read())
        {
            TxtName.Text = re["Name"].ToString();
            TxtDet.Text = re["Department"].ToString();
            TxtPos.Text = re["Position"].ToString();
        }
        re.Close();
    }

    protected void Btntj_Click(object sender, EventArgs e)
    {
        string ID = DropDownList3.SelectedValue.ToString();
        if (TxtName.Text != "" && TxtDet.Text != "" && TxtStart.Text != "" && TxtEnd.Text != "" && TxtRoom.Text != "")
        {
            string insertsql = string.Format("insert into Scheduling (DocID,DocName,Position,DauyDate,StartTime,EndTime,DetName,ConsultationRoom) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", ID, TxtName.Text,TxtPos.Text, TxtWeek.Text, TxtStart.Text, TxtEnd.Text, TxtDet.Text, TxtRoom.Text);
            DBHelper.GetNonQuery(insertsql);
            Response.Write("<script> alert('添加成功!') </script>");
            TxtDet.Text = "";
            TxtEnd.Text = "";
            TxtName.Text = "";
            TxtPos.Text = "";
            TxtRoom.Text = "";
            TxtStart.Text = "";
        }
        else
        {
            Response.Write("<script> alert('添加失败，信息不能为空！') </script>");
        }
    }


    protected void BtnAll_Click(object sender, EventArgs e)
    {
        Response.Redirect("AllSche.aspx");
    }
}